local NetMessage = {}
NetMessage.__index = NetMessage

Tubes.Networking.NetMessageReader = Tubes.MakeConstructor (NetMessage)

function NetMessage:ctor (umsg)
	self.Usermessage = umsg
end

function NetMessage:BitField ()
	local Bits = {false, false, false, false, false, false, false, false}
	local UChar = self:UChar ()
	local Weight = 128
	for i = 1, 8 do
		if UChar >= Weight then
			Bits [9 - i] = true
			UChar = UChar - Weight
		end
		Weight = Weight / 2
	end
	return unpack (Bits)
end

function NetMessage:Char ()
	return self.Usermessage:ReadChar ()
end

function NetMessage:Float ()
	return self.Usermessage:ReadFloat ()
end

function NetMessage:GetSource ()
	return "Server"
end

function NetMessage:Long ()
	return self.Usermessage:ReadLong ()
end

function NetMessage:Player ()
	return ents.GetByIndex (self:UChar ())
end

function NetMessage:Short ()
	return self.Usermessage:ReadShort ()
end

function NetMessage:String ()
	return self.Usermessage:ReadString ()
end

function NetMessage:UChar ()
	return self.Usermessage:ReadChar () + 128
end

function NetMessage:ULong ()
	return self.Usermessage:ReadLong () + 2147483648
end

function NetMessage:UShort (value)
	return self.Usermessage:ReadShort () + 32768
end